{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "view-in-github"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/madaan/self-refine/blob/main/colabs/Visual-Self-Refine-GPT4V.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "IzaKOLGHnTFz"
      },
      "source": [
        "## Install stuff"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 8,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "WnR_4HRfm9Zj",
        "outputId": "33ae1c29-cbdf-47c4-b7d4-776b90adcda1"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "\u001b[?25l     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/70.0 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K     \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[90m╺\u001b[0m\u001b[90m━━━━\u001b[0m \u001b[32m61.4/70.0 kB\u001b[0m \u001b[31m2.2 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m70.0/70.0 kB\u001b[0m \u001b[31m1.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Building wheel for folium (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n",
            "datascience 0.17.6 requires folium>=0.9.1, but you have folium 0.2.1 which is incompatible.\n",
            "geemap 0.28.2 requires folium>=0.13.0, but you have folium 0.2.1 which is incompatible.\u001b[0m\u001b[31m\n",
            "\u001b[0m\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n",
            "lida 0.0.10 requires fastapi, which is not installed.\n",
            "lida 0.0.10 requires kaleido, which is not installed.\n",
            "lida 0.0.10 requires python-multipart, which is not installed.\n",
            "lida 0.0.10 requires uvicorn, which is not installed.\n",
            "fiona 1.9.5 requires attrs>=19.2.0, but you have attrs 18.2.0 which is incompatible.\n",
            "jsonschema 4.19.2 requires attrs>=22.2.0, but you have attrs 18.2.0 which is incompatible.\n",
            "referencing 0.31.0 requires attrs>=22.2.0, but you have attrs 18.2.0 which is incompatible.\u001b[0m\u001b[31m\n",
            "Reading package lists... Done\n",
            "Building dependency tree... Done\n",
            "Reading state information... Done\n",
            "The following additional packages will be installed:\n",
            "  dvisvgm fonts-droid-fallback fonts-lmodern fonts-noto-mono fonts-urw-base35 libfontenc1 libgs9\n",
            "  libgs9-common libidn12 libijs-0.35 libjbig2dec0 libkpathsea6 libptexenc1 libsynctex2 libteckit0\n",
            "  libtexlua53 libtexluajit2 libwoff1 libzzip-0-13 lmodern poppler-data t1utils tex-common\n",
            "  texlive-base texlive-binaries texlive-latex-base xfonts-encodings xfonts-utils\n",
            "Suggested packages:\n",
            "  fonts-noto fonts-freefont-otf | fonts-freefont-ttf fonts-texgyre poppler-utils ghostscript\n",
            "  fonts-japanese-mincho | fonts-ipafont-mincho fonts-japanese-gothic | fonts-ipafont-gothic\n",
            "  fonts-arphic-ukai fonts-arphic-uming fonts-nanum debhelper gv | postscript-viewer perl-tk xpdf\n",
            "  | pdf-viewer xzdec texlive-latex-base-doc texlive-latex-recommended-doc texlive-luatex\n",
            "  texlive-pstricks\n",
            "The following NEW packages will be installed:\n",
            "  dvisvgm fonts-droid-fallback fonts-lmodern fonts-noto-mono fonts-urw-base35 libfontenc1 libgs9\n",
            "  libgs9-common libidn12 libijs-0.35 libjbig2dec0 libkpathsea6 libptexenc1 libsynctex2 libteckit0\n",
            "  libtexlua53 libtexluajit2 libwoff1 libzzip-0-13 lmodern poppler-data t1utils tex-common\n",
            "  texlive-base texlive-binaries texlive-latex-base texlive-latex-recommended xfonts-encodings\n",
            "  xfonts-utils\n",
            "0 upgraded, 29 newly installed, 0 to remove and 15 not upgraded.\n",
            "Need to get 80.1 MB of archives.\n",
            "After this operation, 254 MB of additional disk space will be used.\n",
            "Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 fonts-droid-fallback all 1:6.0.1r16-1.1build1 [1,805 kB]\n",
            "Get:2 http://archive.ubuntu.com/ubuntu jammy/main amd64 poppler-data all 0.4.11-1 [2,171 kB]\n",
            "Get:3 http://archive.ubuntu.com/ubuntu jammy/universe amd64 tex-common all 6.17 [33.7 kB]\n",
            "Get:4 http://archive.ubuntu.com/ubuntu jammy/main amd64 fonts-urw-base35 all 20200910-1 [6,367 kB]\n",
            "Get:5 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 libgs9-common all 9.55.0~dfsg1-0ubuntu5.5 [752 kB]\n",
            "Get:6 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 libidn12 amd64 1.38-4ubuntu1 [60.0 kB]\n",
            "Get:7 http://archive.ubuntu.com/ubuntu jammy/main amd64 libijs-0.35 amd64 0.35-15build2 [16.5 kB]\n",
            "Get:8 http://archive.ubuntu.com/ubuntu jammy/main amd64 libjbig2dec0 amd64 0.19-3build2 [64.7 kB]\n",
            "Get:9 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 libgs9 amd64 9.55.0~dfsg1-0ubuntu5.5 [5,030 kB]\n",
            "Get:10 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 libkpathsea6 amd64 2021.20210626.59705-1ubuntu0.1 [60.3 kB]\n",
            "Get:11 http://archive.ubuntu.com/ubuntu jammy/main amd64 libwoff1 amd64 1.0.2-1build4 [45.2 kB]\n",
            "Get:12 http://archive.ubuntu.com/ubuntu jammy/universe amd64 dvisvgm amd64 2.13.1-1 [1,221 kB]\n",
            "Get:13 http://archive.ubuntu.com/ubuntu jammy/universe amd64 fonts-lmodern all 2.004.5-6.1 [4,532 kB]\n",
            "Get:14 http://archive.ubuntu.com/ubuntu jammy/main amd64 fonts-noto-mono all 20201225-1build1 [397 kB]\n",
            "Get:15 http://archive.ubuntu.com/ubuntu jammy/main amd64 libfontenc1 amd64 1:1.1.4-1build3 [14.7 kB]\n",
            "Get:16 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 libptexenc1 amd64 2021.20210626.59705-1ubuntu0.1 [39.1 kB]\n",
            "Get:17 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 libsynctex2 amd64 2021.20210626.59705-1ubuntu0.1 [55.5 kB]\n",
            "Get:18 http://archive.ubuntu.com/ubuntu jammy/universe amd64 libteckit0 amd64 2.5.11+ds1-1 [421 kB]\n",
            "Get:19 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 libtexlua53 amd64 2021.20210626.59705-1ubuntu0.1 [120 kB]\n",
            "Get:20 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 libtexluajit2 amd64 2021.20210626.59705-1ubuntu0.1 [267 kB]\n",
            "Get:21 http://archive.ubuntu.com/ubuntu jammy/universe amd64 libzzip-0-13 amd64 0.13.72+dfsg.1-1.1 [27.0 kB]\n",
            "Get:22 http://archive.ubuntu.com/ubuntu jammy/main amd64 xfonts-encodings all 1:1.0.5-0ubuntu2 [578 kB]\n",
            "Get:23 http://archive.ubuntu.com/ubuntu jammy/main amd64 xfonts-utils amd64 1:7.7+6build2 [94.6 kB]\n",
            "Get:24 http://archive.ubuntu.com/ubuntu jammy/universe amd64 lmodern all 2.004.5-6.1 [9,471 kB]\n",
            "Get:25 http://archive.ubuntu.com/ubuntu jammy/main amd64 t1utils amd64 1.41-4build2 [61.3 kB]\n",
            "Get:26 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 texlive-binaries amd64 2021.20210626.59705-1ubuntu0.1 [9,848 kB]\n",
            "Get:27 http://archive.ubuntu.com/ubuntu jammy/universe amd64 texlive-base all 2021.20220204-1 [21.0 MB]\n",
            "Get:28 http://archive.ubuntu.com/ubuntu jammy/universe amd64 texlive-latex-base all 2021.20220204-1 [1,128 kB]\n",
            "Get:29 http://archive.ubuntu.com/ubuntu jammy/universe amd64 texlive-latex-recommended all 2021.20220204-1 [14.4 MB]\n",
            "Fetched 80.1 MB in 1s (58.5 MB/s)\n",
            "Preconfiguring packages ...\n",
            "Selecting previously unselected package fonts-droid-fallback.\n",
            "(Reading database ... 120882 files and directories currently installed.)\n",
            "Preparing to unpack .../00-fonts-droid-fallback_1%3a6.0.1r16-1.1build1_all.deb ...\n",
            "Unpacking fonts-droid-fallback (1:6.0.1r16-1.1build1) ...\n",
            "Selecting previously unselected package poppler-data.\n",
            "Preparing to unpack .../01-poppler-data_0.4.11-1_all.deb ...\n",
            "Unpacking poppler-data (0.4.11-1) ...\n",
            "Selecting previously unselected package tex-common.\n",
            "Preparing to unpack .../02-tex-common_6.17_all.deb ...\n",
            "Unpacking tex-common (6.17) ...\n",
            "Selecting previously unselected package fonts-urw-base35.\n",
            "Preparing to unpack .../03-fonts-urw-base35_20200910-1_all.deb ...\n",
            "Unpacking fonts-urw-base35 (20200910-1) ...\n",
            "Selecting previously unselected package libgs9-common.\n",
            "Preparing to unpack .../04-libgs9-common_9.55.0~dfsg1-0ubuntu5.5_all.deb ...\n",
            "Unpacking libgs9-common (9.55.0~dfsg1-0ubuntu5.5) ...\n",
            "Selecting previously unselected package libidn12:amd64.\n",
            "Preparing to unpack .../05-libidn12_1.38-4ubuntu1_amd64.deb ...\n",
            "Unpacking libidn12:amd64 (1.38-4ubuntu1) ...\n",
            "Selecting previously unselected package libijs-0.35:amd64.\n",
            "Preparing to unpack .../06-libijs-0.35_0.35-15build2_amd64.deb ...\n",
            "Unpacking libijs-0.35:amd64 (0.35-15build2) ...\n",
            "Selecting previously unselected package libjbig2dec0:amd64.\n",
            "Preparing to unpack .../07-libjbig2dec0_0.19-3build2_amd64.deb ...\n",
            "Unpacking libjbig2dec0:amd64 (0.19-3build2) ...\n",
            "Selecting previously unselected package libgs9:amd64.\n",
            "Preparing to unpack .../08-libgs9_9.55.0~dfsg1-0ubuntu5.5_amd64.deb ...\n",
            "Unpacking libgs9:amd64 (9.55.0~dfsg1-0ubuntu5.5) ...\n",
            "Selecting previously unselected package libkpathsea6:amd64.\n",
            "Preparing to unpack .../09-libkpathsea6_2021.20210626.59705-1ubuntu0.1_amd64.deb ...\n",
            "Unpacking libkpathsea6:amd64 (2021.20210626.59705-1ubuntu0.1) ...\n",
            "Selecting previously unselected package libwoff1:amd64.\n",
            "Preparing to unpack .../10-libwoff1_1.0.2-1build4_amd64.deb ...\n",
            "Unpacking libwoff1:amd64 (1.0.2-1build4) ...\n",
            "Selecting previously unselected package dvisvgm.\n",
            "Preparing to unpack .../11-dvisvgm_2.13.1-1_amd64.deb ...\n",
            "Unpacking dvisvgm (2.13.1-1) ...\n",
            "Selecting previously unselected package fonts-lmodern.\n",
            "Preparing to unpack .../12-fonts-lmodern_2.004.5-6.1_all.deb ...\n",
            "Unpacking fonts-lmodern (2.004.5-6.1) ...\n",
            "Selecting previously unselected package fonts-noto-mono.\n",
            "Preparing to unpack .../13-fonts-noto-mono_20201225-1build1_all.deb ...\n",
            "Unpacking fonts-noto-mono (20201225-1build1) ...\n",
            "Selecting previously unselected package libfontenc1:amd64.\n",
            "Preparing to unpack .../14-libfontenc1_1%3a1.1.4-1build3_amd64.deb ...\n",
            "Unpacking libfontenc1:amd64 (1:1.1.4-1build3) ...\n",
            "Selecting previously unselected package libptexenc1:amd64.\n",
            "Preparing to unpack .../15-libptexenc1_2021.20210626.59705-1ubuntu0.1_amd64.deb ...\n",
            "Unpacking libptexenc1:amd64 (2021.20210626.59705-1ubuntu0.1) ...\n",
            "Selecting previously unselected package libsynctex2:amd64.\n",
            "Preparing to unpack .../16-libsynctex2_2021.20210626.59705-1ubuntu0.1_amd64.deb ...\n",
            "Unpacking libsynctex2:amd64 (2021.20210626.59705-1ubuntu0.1) ...\n",
            "Selecting previously unselected package libteckit0:amd64.\n",
            "Preparing to unpack .../17-libteckit0_2.5.11+ds1-1_amd64.deb ...\n",
            "Unpacking libteckit0:amd64 (2.5.11+ds1-1) ...\n",
            "Selecting previously unselected package libtexlua53:amd64.\n",
            "Preparing to unpack .../18-libtexlua53_2021.20210626.59705-1ubuntu0.1_amd64.deb ...\n",
            "Unpacking libtexlua53:amd64 (2021.20210626.59705-1ubuntu0.1) ...\n",
            "Selecting previously unselected package libtexluajit2:amd64.\n",
            "Preparing to unpack .../19-libtexluajit2_2021.20210626.59705-1ubuntu0.1_amd64.deb ...\n",
            "Unpacking libtexluajit2:amd64 (2021.20210626.59705-1ubuntu0.1) ...\n",
            "Selecting previously unselected package libzzip-0-13:amd64.\n",
            "Preparing to unpack .../20-libzzip-0-13_0.13.72+dfsg.1-1.1_amd64.deb ...\n",
            "Unpacking libzzip-0-13:amd64 (0.13.72+dfsg.1-1.1) ...\n",
            "Selecting previously unselected package xfonts-encodings.\n",
            "Preparing to unpack .../21-xfonts-encodings_1%3a1.0.5-0ubuntu2_all.deb ...\n",
            "Unpacking xfonts-encodings (1:1.0.5-0ubuntu2) ...\n",
            "Selecting previously unselected package xfonts-utils.\n",
            "Preparing to unpack .../22-xfonts-utils_1%3a7.7+6build2_amd64.deb ...\n",
            "Unpacking xfonts-utils (1:7.7+6build2) ...\n",
            "Selecting previously unselected package lmodern.\n",
            "Preparing to unpack .../23-lmodern_2.004.5-6.1_all.deb ...\n",
            "Unpacking lmodern (2.004.5-6.1) ...\n",
            "Selecting previously unselected package t1utils.\n",
            "Preparing to unpack .../24-t1utils_1.41-4build2_amd64.deb ...\n",
            "Unpacking t1utils (1.41-4build2) ...\n",
            "Selecting previously unselected package texlive-binaries.\n",
            "Preparing to unpack .../25-texlive-binaries_2021.20210626.59705-1ubuntu0.1_amd64.deb ...\n",
            "Unpacking texlive-binaries (2021.20210626.59705-1ubuntu0.1) ...\n",
            "Selecting previously unselected package texlive-base.\n",
            "Preparing to unpack .../26-texlive-base_2021.20220204-1_all.deb ...\n",
            "Unpacking texlive-base (2021.20220204-1) ...\n",
            "Selecting previously unselected package texlive-latex-base.\n",
            "Preparing to unpack .../27-texlive-latex-base_2021.20220204-1_all.deb ...\n",
            "Unpacking texlive-latex-base (2021.20220204-1) ...\n",
            "Selecting previously unselected package texlive-latex-recommended.\n",
            "Preparing to unpack .../28-texlive-latex-recommended_2021.20220204-1_all.deb ...\n",
            "Unpacking texlive-latex-recommended (2021.20220204-1) ...\n",
            "Setting up fonts-noto-mono (20201225-1build1) ...\n",
            "Setting up libwoff1:amd64 (1.0.2-1build4) ...\n",
            "Setting up libtexlua53:amd64 (2021.20210626.59705-1ubuntu0.1) ...\n",
            "Setting up libijs-0.35:amd64 (0.35-15build2) ...\n",
            "Setting up libtexluajit2:amd64 (2021.20210626.59705-1ubuntu0.1) ...\n",
            "Setting up libzzip-0-13:amd64 (0.13.72+dfsg.1-1.1) ...\n",
            "Setting up fonts-urw-base35 (20200910-1) ...\n",
            "Setting up poppler-data (0.4.11-1) ...\n",
            "Setting up tex-common (6.17) ...\n",
            "update-language: texlive-base not installed and configured, doing nothing!\n",
            "Setting up libfontenc1:amd64 (1:1.1.4-1build3) ...\n",
            "Setting up libjbig2dec0:amd64 (0.19-3build2) ...\n",
            "Setting up libteckit0:amd64 (2.5.11+ds1-1) ...\n",
            "Setting up xfonts-encodings (1:1.0.5-0ubuntu2) ...\n",
            "Setting up t1utils (1.41-4build2) ...\n",
            "Setting up libidn12:amd64 (1.38-4ubuntu1) ...\n",
            "Setting up libkpathsea6:amd64 (2021.20210626.59705-1ubuntu0.1) ...\n",
            "Setting up fonts-lmodern (2.004.5-6.1) ...\n",
            "Setting up fonts-droid-fallback (1:6.0.1r16-1.1build1) ...\n",
            "Setting up libsynctex2:amd64 (2021.20210626.59705-1ubuntu0.1) ...\n",
            "Setting up libgs9-common (9.55.0~dfsg1-0ubuntu5.5) ...\n",
            "Setting up libgs9:amd64 (9.55.0~dfsg1-0ubuntu5.5) ...\n",
            "Setting up dvisvgm (2.13.1-1) ...\n",
            "Setting up xfonts-utils (1:7.7+6build2) ...\n",
            "Setting up libptexenc1:amd64 (2021.20210626.59705-1ubuntu0.1) ...\n",
            "Setting up texlive-binaries (2021.20210626.59705-1ubuntu0.1) ...\n",
            "update-alternatives: using /usr/bin/xdvi-xaw to provide /usr/bin/xdvi.bin (xdvi.bin) in auto mode\n",
            "update-alternatives: using /usr/bin/bibtex.original to provide /usr/bin/bibtex (bibtex) in auto mode\n",
            "Setting up lmodern (2.004.5-6.1) ...\n",
            "Setting up texlive-base (2021.20220204-1) ...\n",
            "/usr/bin/ucfr\n",
            "/usr/bin/ucfr\n",
            "/usr/bin/ucfr\n",
            "/usr/bin/ucfr\n",
            "mktexlsr: Updating /var/lib/texmf/ls-R-TEXLIVEDIST... \n",
            "mktexlsr: Updating /var/lib/texmf/ls-R-TEXMFMAIN... \n",
            "mktexlsr: Updating /var/lib/texmf/ls-R... \n",
            "mktexlsr: Done.\n",
            "tl-paper: setting paper size for dvips to a4: /var/lib/texmf/dvips/config/config-paper.ps\n",
            "tl-paper: setting paper size for dvipdfmx to a4: /var/lib/texmf/dvipdfmx/dvipdfmx-paper.cfg\n",
            "tl-paper: setting paper size for xdvi to a4: /var/lib/texmf/xdvi/XDvi-paper\n",
            "tl-paper: setting paper size for pdftex to a4: /var/lib/texmf/tex/generic/tex-ini-files/pdftexconfig.tex\n",
            "Setting up texlive-latex-base (2021.20220204-1) ...\n",
            "Setting up texlive-latex-recommended (2021.20220204-1) ...\n",
            "Processing triggers for libc-bin (2.35-0ubuntu3.4) ...\n",
            "/sbin/ldconfig.real: /usr/local/lib/libtbbmalloc.so.2 is not a symbolic link\n",
            "\n",
            "/sbin/ldconfig.real: /usr/local/lib/libtbbmalloc_proxy.so.2 is not a symbolic link\n",
            "\n",
            "/sbin/ldconfig.real: /usr/local/lib/libtbbbind_2_0.so.3 is not a symbolic link\n",
            "\n",
            "/sbin/ldconfig.real: /usr/local/lib/libtbb.so.12 is not a symbolic link\n",
            "\n",
            "/sbin/ldconfig.real: /usr/local/lib/libtbbbind.so.3 is not a symbolic link\n",
            "\n",
            "/sbin/ldconfig.real: /usr/local/lib/libtbbbind_2_5.so.3 is not a symbolic link\n",
            "\n",
            "Processing triggers for man-db (2.10.2-1) ...\n",
            "Processing triggers for fontconfig (2.13.1-4.2ubuntu5) ...\n",
            "Processing triggers for tex-common (6.17) ...\n",
            "Running updmap-sys. This may take some time... done.\n",
            "Running mktexlsr /var/lib/texmf ... done.\n",
            "Building format(s) --all.\n",
            "\tThis may take some time... done.\n",
            "Reading package lists... Done\n",
            "Building dependency tree... Done\n",
            "Reading state information... Done\n",
            "The following additional packages will be installed:\n",
            "  fonts-lato fonts-texgyre libapache-pom-java libcommons-logging-java libcommons-parent-java\n",
            "  libfontbox-java libpdfbox-java libruby3.0 preview-latex-style rake ruby ruby-net-telnet\n",
            "  ruby-rubygems ruby-webrick ruby-xmlrpc ruby3.0 rubygems-integration tex-gyre\n",
            "  texlive-fonts-recommended texlive-pictures texlive-plain-generic tipa\n",
            "Suggested packages:\n",
            "  libavalon-framework-java libcommons-logging-java-doc libexcalibur-logkit-java liblog4j1.2-java ri\n",
            "  ruby-dev bundler texlive-fonts-recommended-doc python3-pygments icc-profiles libfile-which-perl\n",
            "  libspreadsheet-parseexcel-perl texlive-latex-extra-doc dot2tex prerex texlive-pictures-doc\n",
            "  vprerex default-jre-headless tipa-doc\n",
            "The following NEW packages will be installed:\n",
            "  fonts-lato fonts-texgyre libapache-pom-java libcommons-logging-java libcommons-parent-java\n",
            "  libfontbox-java libpdfbox-java libruby3.0 preview-latex-style rake ruby ruby-net-telnet\n",
            "  ruby-rubygems ruby-webrick ruby-xmlrpc ruby3.0 rubygems-integration tex-gyre\n",
            "  texlive-fonts-recommended texlive-latex-extra texlive-pictures texlive-plain-generic tipa\n",
            "0 upgraded, 23 newly installed, 0 to remove and 15 not upgraded.\n",
            "Need to get 88.4 MB of archives.\n",
            "After this operation, 298 MB of additional disk space will be used.\n",
            "Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 fonts-lato all 2.0-2.1 [2,696 kB]\n",
            "Get:2 http://archive.ubuntu.com/ubuntu jammy/universe amd64 fonts-texgyre all 20180621-3.1 [10.2 MB]\n",
            "Get:3 http://archive.ubuntu.com/ubuntu jammy/universe amd64 libapache-pom-java all 18-1 [4,720 B]\n",
            "Get:4 http://archive.ubuntu.com/ubuntu jammy/universe amd64 libcommons-parent-java all 43-1 [10.8 kB]\n",
            "Get:5 http://archive.ubuntu.com/ubuntu jammy/universe amd64 libcommons-logging-java all 1.2-2 [60.3 kB]\n",
            "Get:6 http://archive.ubuntu.com/ubuntu jammy/main amd64 rubygems-integration all 1.18 [5,336 B]\n",
            "Get:7 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 ruby3.0 amd64 3.0.2-7ubuntu2.4 [50.1 kB]\n",
            "Get:8 http://archive.ubuntu.com/ubuntu jammy/main amd64 ruby-rubygems all 3.3.5-2 [228 kB]\n",
            "Get:9 http://archive.ubuntu.com/ubuntu jammy/main amd64 ruby amd64 1:3.0~exp1 [5,100 B]\n",
            "Get:10 http://archive.ubuntu.com/ubuntu jammy/main amd64 rake all 13.0.6-2 [61.7 kB]\n",
            "Get:11 http://archive.ubuntu.com/ubuntu jammy/main amd64 ruby-net-telnet all 0.1.1-2 [12.6 kB]\n",
            "Get:12 http://archive.ubuntu.com/ubuntu jammy/universe amd64 ruby-webrick all 1.7.0-3 [51.8 kB]\n",
            "Get:13 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 ruby-xmlrpc all 0.3.2-1ubuntu0.1 [24.9 kB]\n",
            "Get:14 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 libruby3.0 amd64 3.0.2-7ubuntu2.4 [5,113 kB]\n",
            "Get:15 http://archive.ubuntu.com/ubuntu jammy/universe amd64 preview-latex-style all 12.2-1ubuntu1 [185 kB]\n",
            "Get:16 http://archive.ubuntu.com/ubuntu jammy/universe amd64 tex-gyre all 20180621-3.1 [6,209 kB]\n",
            "Get:17 http://archive.ubuntu.com/ubuntu jammy/universe amd64 texlive-fonts-recommended all 2021.20220204-1 [4,972 kB]\n",
            "Get:18 http://archive.ubuntu.com/ubuntu jammy/universe amd64 libfontbox-java all 1:1.8.16-2 [207 kB]\n",
            "Get:19 http://archive.ubuntu.com/ubuntu jammy/universe amd64 libpdfbox-java all 1:1.8.16-2 [5,199 kB]\n",
            "Get:20 http://archive.ubuntu.com/ubuntu jammy/universe amd64 texlive-pictures all 2021.20220204-1 [8,720 kB]\n",
            "Get:21 http://archive.ubuntu.com/ubuntu jammy/universe amd64 texlive-latex-extra all 2021.20220204-1 [13.9 MB]\n",
            "Get:22 http://archive.ubuntu.com/ubuntu jammy/universe amd64 texlive-plain-generic all 2021.20220204-1 [27.5 MB]\n",
            "Ign:22 http://archive.ubuntu.com/ubuntu jammy/universe amd64 texlive-plain-generic all 2021.20220204-1\n",
            "Get:23 http://archive.ubuntu.com/ubuntu jammy/universe amd64 tipa all 2:1.3-21 [2,967 kB]\n",
            "Get:22 http://archive.ubuntu.com/ubuntu jammy/universe amd64 texlive-plain-generic all 2021.20220204-1 [27.5 MB]\n",
            "Fetched 64.6 MB in 15s (4,201 kB/s)\n",
            "Selecting previously unselected package fonts-lato.\n",
            "(Reading database ... 130394 files and directories currently installed.)\n",
            "Preparing to unpack .../00-fonts-lato_2.0-2.1_all.deb ...\n",
            "Unpacking fonts-lato (2.0-2.1) ...\n",
            "Selecting previously unselected package fonts-texgyre.\n",
            "Preparing to unpack .../01-fonts-texgyre_20180621-3.1_all.deb ...\n",
            "Unpacking fonts-texgyre (20180621-3.1) ...\n",
            "Selecting previously unselected package libapache-pom-java.\n",
            "Preparing to unpack .../02-libapache-pom-java_18-1_all.deb ...\n",
            "Unpacking libapache-pom-java (18-1) ...\n",
            "Selecting previously unselected package libcommons-parent-java.\n",
            "Preparing to unpack .../03-libcommons-parent-java_43-1_all.deb ...\n",
            "Unpacking libcommons-parent-java (43-1) ...\n",
            "Selecting previously unselected package libcommons-logging-java.\n",
            "Preparing to unpack .../04-libcommons-logging-java_1.2-2_all.deb ...\n",
            "Unpacking libcommons-logging-java (1.2-2) ...\n",
            "Selecting previously unselected package rubygems-integration.\n",
            "Preparing to unpack .../05-rubygems-integration_1.18_all.deb ...\n",
            "Unpacking rubygems-integration (1.18) ...\n",
            "Selecting previously unselected package ruby3.0.\n",
            "Preparing to unpack .../06-ruby3.0_3.0.2-7ubuntu2.4_amd64.deb ...\n",
            "Unpacking ruby3.0 (3.0.2-7ubuntu2.4) ...\n",
            "Selecting previously unselected package ruby-rubygems.\n",
            "Preparing to unpack .../07-ruby-rubygems_3.3.5-2_all.deb ...\n",
            "Unpacking ruby-rubygems (3.3.5-2) ...\n",
            "Selecting previously unselected package ruby.\n",
            "Preparing to unpack .../08-ruby_1%3a3.0~exp1_amd64.deb ...\n",
            "Unpacking ruby (1:3.0~exp1) ...\n",
            "Selecting previously unselected package rake.\n",
            "Preparing to unpack .../09-rake_13.0.6-2_all.deb ...\n",
            "Unpacking rake (13.0.6-2) ...\n",
            "Selecting previously unselected package ruby-net-telnet.\n",
            "Preparing to unpack .../10-ruby-net-telnet_0.1.1-2_all.deb ...\n",
            "Unpacking ruby-net-telnet (0.1.1-2) ...\n",
            "Selecting previously unselected package ruby-webrick.\n",
            "Preparing to unpack .../11-ruby-webrick_1.7.0-3_all.deb ...\n",
            "Unpacking ruby-webrick (1.7.0-3) ...\n",
            "Selecting previously unselected package ruby-xmlrpc.\n",
            "Preparing to unpack .../12-ruby-xmlrpc_0.3.2-1ubuntu0.1_all.deb ...\n",
            "Unpacking ruby-xmlrpc (0.3.2-1ubuntu0.1) ...\n",
            "Selecting previously unselected package libruby3.0:amd64.\n",
            "Preparing to unpack .../13-libruby3.0_3.0.2-7ubuntu2.4_amd64.deb ...\n",
            "Unpacking libruby3.0:amd64 (3.0.2-7ubuntu2.4) ...\n",
            "Selecting previously unselected package preview-latex-style.\n",
            "Preparing to unpack .../14-preview-latex-style_12.2-1ubuntu1_all.deb ...\n",
            "Unpacking preview-latex-style (12.2-1ubuntu1) ...\n",
            "Selecting previously unselected package tex-gyre.\n",
            "Preparing to unpack .../15-tex-gyre_20180621-3.1_all.deb ...\n",
            "Unpacking tex-gyre (20180621-3.1) ...\n",
            "Selecting previously unselected package texlive-fonts-recommended.\n",
            "Preparing to unpack .../16-texlive-fonts-recommended_2021.20220204-1_all.deb ...\n",
            "Unpacking texlive-fonts-recommended (2021.20220204-1) ...\n",
            "Selecting previously unselected package libfontbox-java.\n",
            "Preparing to unpack .../17-libfontbox-java_1%3a1.8.16-2_all.deb ...\n",
            "Unpacking libfontbox-java (1:1.8.16-2) ...\n",
            "Selecting previously unselected package libpdfbox-java.\n",
            "Preparing to unpack .../18-libpdfbox-java_1%3a1.8.16-2_all.deb ...\n",
            "Unpacking libpdfbox-java (1:1.8.16-2) ...\n",
            "Selecting previously unselected package texlive-pictures.\n",
            "Preparing to unpack .../19-texlive-pictures_2021.20220204-1_all.deb ...\n",
            "Unpacking texlive-pictures (2021.20220204-1) ...\n",
            "Selecting previously unselected package texlive-latex-extra.\n",
            "Preparing to unpack .../20-texlive-latex-extra_2021.20220204-1_all.deb ...\n",
            "Unpacking texlive-latex-extra (2021.20220204-1) ...\n",
            "Selecting previously unselected package texlive-plain-generic.\n",
            "Preparing to unpack .../21-texlive-plain-generic_2021.20220204-1_all.deb ...\n",
            "Unpacking texlive-plain-generic (2021.20220204-1) ...\n",
            "Selecting previously unselected package tipa.\n",
            "Preparing to unpack .../22-tipa_2%3a1.3-21_all.deb ...\n",
            "Unpacking tipa (2:1.3-21) ...\n",
            "Setting up fonts-lato (2.0-2.1) ...\n",
            "Setting up preview-latex-style (12.2-1ubuntu1) ...\n",
            "Setting up libfontbox-java (1:1.8.16-2) ...\n",
            "Setting up texlive-plain-generic (2021.20220204-1) ...\n",
            "Setting up rubygems-integration (1.18) ...\n",
            "Setting up libapache-pom-java (18-1) ...\n",
            "Setting up ruby-net-telnet (0.1.1-2) ...\n",
            "Setting up fonts-texgyre (20180621-3.1) ...\n",
            "Setting up texlive-pictures (2021.20220204-1) ...\n",
            "Setting up ruby-webrick (1.7.0-3) ...\n",
            "Setting up texlive-fonts-recommended (2021.20220204-1) ...\n",
            "Setting up tipa (2:1.3-21) ...\n",
            "Setting up ruby-xmlrpc (0.3.2-1ubuntu0.1) ...\n",
            "Setting up tex-gyre (20180621-3.1) ...\n",
            "Setting up libpdfbox-java (1:1.8.16-2) ...\n",
            "Setting up libcommons-parent-java (43-1) ...\n",
            "Setting up libcommons-logging-java (1.2-2) ...\n",
            "Setting up texlive-latex-extra (2021.20220204-1) ...\n",
            "Setting up libruby3.0:amd64 (3.0.2-7ubuntu2.4) ...\n",
            "Setting up ruby3.0 (3.0.2-7ubuntu2.4) ...\n",
            "Setting up ruby (1:3.0~exp1) ...\n",
            "Setting up rake (13.0.6-2) ...\n",
            "Setting up ruby-rubygems (3.3.5-2) ...\n",
            "Processing triggers for man-db (2.10.2-1) ...\n",
            "Processing triggers for tex-common (6.17) ...\n",
            "Running mktexlsr. This may take some time... done.\n",
            "Running updmap-sys. This may take some time... done.\n",
            "Running mktexlsr /var/lib/texmf ... done.\n",
            "Building format(s) --all.\n",
            "\tThis may take some time... done.\n",
            "Processing triggers for fontconfig (2.13.1-4.2ubuntu5) ...\n",
            "Processing triggers for libc-bin (2.35-0ubuntu3.4) ...\n",
            "/sbin/ldconfig.real: /usr/local/lib/libtbbmalloc.so.2 is not a symbolic link\n",
            "\n",
            "/sbin/ldconfig.real: /usr/local/lib/libtbbmalloc_proxy.so.2 is not a symbolic link\n",
            "\n",
            "/sbin/ldconfig.real: /usr/local/lib/libtbbbind_2_0.so.3 is not a symbolic link\n",
            "\n",
            "/sbin/ldconfig.real: /usr/local/lib/libtbb.so.12 is not a symbolic link\n",
            "\n",
            "/sbin/ldconfig.real: /usr/local/lib/libtbbbind.so.3 is not a symbolic link\n",
            "\n",
            "/sbin/ldconfig.real: /usr/local/lib/libtbbbind_2_5.so.3 is not a symbolic link\n",
            "\n",
            "Reading package lists... Done\n",
            "Building dependency tree... Done\n",
            "Reading state information... Done\n",
            "The following additional packages will be installed:\n",
            "  ghostscript\n",
            "Suggested packages:\n",
            "  ghostscript-x\n",
            "The following NEW packages will be installed:\n",
            "  dvipng ghostscript\n",
            "0 upgraded, 2 newly installed, 0 to remove and 15 not upgraded.\n",
            "Need to get 128 kB of archives.\n",
            "After this operation, 414 kB of additional disk space will be used.\n",
            "Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 ghostscript amd64 9.55.0~dfsg1-0ubuntu5.5 [49.5 kB]\n",
            "Get:2 http://archive.ubuntu.com/ubuntu jammy/universe amd64 dvipng amd64 1.15-1.1 [78.9 kB]\n",
            "Fetched 128 kB in 1s (181 kB/s)\n",
            "Selecting previously unselected package ghostscript.\n",
            "(Reading database ... 157125 files and directories currently installed.)\n",
            "Preparing to unpack .../ghostscript_9.55.0~dfsg1-0ubuntu5.5_amd64.deb ...\n",
            "Unpacking ghostscript (9.55.0~dfsg1-0ubuntu5.5) ...\n",
            "Selecting previously unselected package dvipng.\n",
            "Preparing to unpack .../dvipng_1.15-1.1_amd64.deb ...\n",
            "Unpacking dvipng (1.15-1.1) ...\n",
            "Setting up ghostscript (9.55.0~dfsg1-0ubuntu5.5) ...\n",
            "Setting up dvipng (1.15-1.1) ...\n",
            "Processing triggers for man-db (2.10.2-1) ...\n",
            "Reading package lists... Done\n",
            "Building dependency tree... Done\n",
            "Reading state information... Done\n",
            "The following additional packages will be installed:\n",
            "  gsfonts imagemagick-6-common imagemagick-6.q16 libdjvulibre-text libdjvulibre21 libfftw3-double3\n",
            "  libjxr-tools libjxr0 liblqr-1-0 libmagickcore-6.q16-6 libmagickcore-6.q16-6-extra\n",
            "  libmagickwand-6.q16-6 libnetpbm10 libwmflite-0.2-7 netpbm\n",
            "Suggested packages:\n",
            "  imagemagick-doc autotrace cups-bsd | lpr | lprng enscript gimp gnuplot grads hp2xx html2ps\n",
            "  libwmf-bin mplayer povray radiance sane-utils transfig ufraw-batch libfftw3-bin libfftw3-dev\n",
            "  inkscape\n",
            "The following NEW packages will be installed:\n",
            "  gsfonts imagemagick imagemagick-6-common imagemagick-6.q16 libdjvulibre-text libdjvulibre21\n",
            "  libfftw3-double3 libjxr-tools libjxr0 liblqr-1-0 libmagickcore-6.q16-6\n",
            "  libmagickcore-6.q16-6-extra libmagickwand-6.q16-6 libnetpbm10 libwmflite-0.2-7 netpbm\n",
            "0 upgraded, 16 newly installed, 0 to remove and 15 not upgraded.\n",
            "Need to get 8,405 kB of archives.\n",
            "After this operation, 24.8 MB of additional disk space will be used.\n",
            "Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 libfftw3-double3 amd64 3.3.8-2ubuntu8 [770 kB]\n",
            "Get:2 http://archive.ubuntu.com/ubuntu jammy/universe amd64 liblqr-1-0 amd64 0.4.2-2.1 [27.7 kB]\n",
            "Get:3 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 imagemagick-6-common all 8:6.9.11.60+dfsg-1.3ubuntu0.22.04.3 [63.6 kB]\n",
            "Get:4 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 libmagickcore-6.q16-6 amd64 8:6.9.11.60+dfsg-1.3ubuntu0.22.04.3 [1,788 kB]\n",
            "Get:5 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 libmagickwand-6.q16-6 amd64 8:6.9.11.60+dfsg-1.3ubuntu0.22.04.3 [328 kB]\n",
            "Get:6 http://archive.ubuntu.com/ubuntu jammy/universe amd64 gsfonts all 1:8.11+urwcyr1.0.7~pre44-4.5 [3,120 kB]\n",
            "Get:7 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 imagemagick-6.q16 amd64 8:6.9.11.60+dfsg-1.3ubuntu0.22.04.3 [224 kB]\n",
            "Get:8 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 imagemagick amd64 8:6.9.11.60+dfsg-1.3ubuntu0.22.04.3 [14.6 kB]\n",
            "Get:9 http://archive.ubuntu.com/ubuntu jammy/main amd64 libdjvulibre-text all 3.5.28-2build2 [50.9 kB]\n",
            "Get:10 http://archive.ubuntu.com/ubuntu jammy/main amd64 libdjvulibre21 amd64 3.5.28-2build2 [624 kB]\n",
            "Get:11 http://archive.ubuntu.com/ubuntu jammy/universe amd64 libjxr0 amd64 1.2~git20170615.f752187-5 [174 kB]\n",
            "Get:12 http://archive.ubuntu.com/ubuntu jammy/universe amd64 libjxr-tools amd64 1.2~git20170615.f752187-5 [16.0 kB]\n",
            "Get:13 http://archive.ubuntu.com/ubuntu jammy/main amd64 libwmflite-0.2-7 amd64 0.2.12-5ubuntu1 [68.9 kB]\n",
            "Get:14 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 libmagickcore-6.q16-6-extra amd64 8:6.9.11.60+dfsg-1.3ubuntu0.22.04.3 [70.1 kB]\n",
            "Get:15 http://archive.ubuntu.com/ubuntu jammy/universe amd64 libnetpbm10 amd64 2:10.0-15.4 [59.1 kB]\n",
            "Get:16 http://archive.ubuntu.com/ubuntu jammy/universe amd64 netpbm amd64 2:10.0-15.4 [1,007 kB]\n",
            "Fetched 8,405 kB in 2s (3,934 kB/s)\n",
            "Selecting previously unselected package libfftw3-double3:amd64.\n",
            "(Reading database ... 157205 files and directories currently installed.)\n",
            "Preparing to unpack .../00-libfftw3-double3_3.3.8-2ubuntu8_amd64.deb ...\n",
            "Unpacking libfftw3-double3:amd64 (3.3.8-2ubuntu8) ...\n",
            "Selecting previously unselected package liblqr-1-0:amd64.\n",
            "Preparing to unpack .../01-liblqr-1-0_0.4.2-2.1_amd64.deb ...\n",
            "Unpacking liblqr-1-0:amd64 (0.4.2-2.1) ...\n",
            "Selecting previously unselected package imagemagick-6-common.\n",
            "Preparing to unpack .../02-imagemagick-6-common_8%3a6.9.11.60+dfsg-1.3ubuntu0.22.04.3_all.deb ...\n",
            "Unpacking imagemagick-6-common (8:6.9.11.60+dfsg-1.3ubuntu0.22.04.3) ...\n",
            "Selecting previously unselected package libmagickcore-6.q16-6:amd64.\n",
            "Preparing to unpack .../03-libmagickcore-6.q16-6_8%3a6.9.11.60+dfsg-1.3ubuntu0.22.04.3_amd64.deb ...\n",
            "Unpacking libmagickcore-6.q16-6:amd64 (8:6.9.11.60+dfsg-1.3ubuntu0.22.04.3) ...\n",
            "Selecting previously unselected package libmagickwand-6.q16-6:amd64.\n",
            "Preparing to unpack .../04-libmagickwand-6.q16-6_8%3a6.9.11.60+dfsg-1.3ubuntu0.22.04.3_amd64.deb ...\n",
            "Unpacking libmagickwand-6.q16-6:amd64 (8:6.9.11.60+dfsg-1.3ubuntu0.22.04.3) ...\n",
            "Selecting previously unselected package gsfonts.\n",
            "Preparing to unpack .../05-gsfonts_1%3a8.11+urwcyr1.0.7~pre44-4.5_all.deb ...\n",
            "Unpacking gsfonts (1:8.11+urwcyr1.0.7~pre44-4.5) ...\n",
            "Selecting previously unselected package imagemagick-6.q16.\n",
            "Preparing to unpack .../06-imagemagick-6.q16_8%3a6.9.11.60+dfsg-1.3ubuntu0.22.04.3_amd64.deb ...\n",
            "Unpacking imagemagick-6.q16 (8:6.9.11.60+dfsg-1.3ubuntu0.22.04.3) ...\n",
            "Selecting previously unselected package imagemagick.\n",
            "Preparing to unpack .../07-imagemagick_8%3a6.9.11.60+dfsg-1.3ubuntu0.22.04.3_amd64.deb ...\n",
            "Unpacking imagemagick (8:6.9.11.60+dfsg-1.3ubuntu0.22.04.3) ...\n",
            "Selecting previously unselected package libdjvulibre-text.\n",
            "Preparing to unpack .../08-libdjvulibre-text_3.5.28-2build2_all.deb ...\n",
            "Unpacking libdjvulibre-text (3.5.28-2build2) ...\n",
            "Selecting previously unselected package libdjvulibre21:amd64.\n",
            "Preparing to unpack .../09-libdjvulibre21_3.5.28-2build2_amd64.deb ...\n",
            "Unpacking libdjvulibre21:amd64 (3.5.28-2build2) ...\n",
            "Selecting previously unselected package libjxr0:amd64.\n",
            "Preparing to unpack .../10-libjxr0_1.2~git20170615.f752187-5_amd64.deb ...\n",
            "Unpacking libjxr0:amd64 (1.2~git20170615.f752187-5) ...\n",
            "Selecting previously unselected package libjxr-tools.\n",
            "Preparing to unpack .../11-libjxr-tools_1.2~git20170615.f752187-5_amd64.deb ...\n",
            "Unpacking libjxr-tools (1.2~git20170615.f752187-5) ...\n",
            "Selecting previously unselected package libwmflite-0.2-7:amd64.\n",
            "Preparing to unpack .../12-libwmflite-0.2-7_0.2.12-5ubuntu1_amd64.deb ...\n",
            "Unpacking libwmflite-0.2-7:amd64 (0.2.12-5ubuntu1) ...\n",
            "Selecting previously unselected package libmagickcore-6.q16-6-extra:amd64.\n",
            "Preparing to unpack .../13-libmagickcore-6.q16-6-extra_8%3a6.9.11.60+dfsg-1.3ubuntu0.22.04.3_amd64.deb ...\n",
            "Unpacking libmagickcore-6.q16-6-extra:amd64 (8:6.9.11.60+dfsg-1.3ubuntu0.22.04.3) ...\n",
            "Selecting previously unselected package libnetpbm10.\n",
            "Preparing to unpack .../14-libnetpbm10_2%3a10.0-15.4_amd64.deb ...\n",
            "Unpacking libnetpbm10 (2:10.0-15.4) ...\n",
            "Selecting previously unselected package netpbm.\n",
            "Preparing to unpack .../15-netpbm_2%3a10.0-15.4_amd64.deb ...\n",
            "Unpacking netpbm (2:10.0-15.4) ...\n",
            "Setting up imagemagick-6-common (8:6.9.11.60+dfsg-1.3ubuntu0.22.04.3) ...\n",
            "Setting up libwmflite-0.2-7:amd64 (0.2.12-5ubuntu1) ...\n",
            "Setting up libjxr0:amd64 (1.2~git20170615.f752187-5) ...\n",
            "Setting up libnetpbm10 (2:10.0-15.4) ...\n",
            "Setting up gsfonts (1:8.11+urwcyr1.0.7~pre44-4.5) ...\n",
            "Setting up netpbm (2:10.0-15.4) ...\n",
            "Setting up libfftw3-double3:amd64 (3.3.8-2ubuntu8) ...\n",
            "Setting up liblqr-1-0:amd64 (0.4.2-2.1) ...\n",
            "Setting up libdjvulibre-text (3.5.28-2build2) ...\n",
            "Setting up libjxr-tools (1.2~git20170615.f752187-5) ...\n",
            "Setting up libdjvulibre21:amd64 (3.5.28-2build2) ...\n",
            "Setting up libmagickcore-6.q16-6:amd64 (8:6.9.11.60+dfsg-1.3ubuntu0.22.04.3) ...\n",
            "Setting up libmagickwand-6.q16-6:amd64 (8:6.9.11.60+dfsg-1.3ubuntu0.22.04.3) ...\n",
            "Setting up libmagickcore-6.q16-6-extra:amd64 (8:6.9.11.60+dfsg-1.3ubuntu0.22.04.3) ...\n",
            "Setting up imagemagick-6.q16 (8:6.9.11.60+dfsg-1.3ubuntu0.22.04.3) ...\n",
            "update-alternatives: using /usr/bin/compare-im6.q16 to provide /usr/bin/compare (compare) in auto mode\n",
            "update-alternatives: using /usr/bin/compare-im6.q16 to provide /usr/bin/compare-im6 (compare-im6) in auto mode\n",
            "update-alternatives: using /usr/bin/animate-im6.q16 to provide /usr/bin/animate (animate) in auto mode\n",
            "update-alternatives: using /usr/bin/animate-im6.q16 to provide /usr/bin/animate-im6 (animate-im6) in auto mode\n",
            "update-alternatives: using /usr/bin/convert-im6.q16 to provide /usr/bin/convert (convert) in auto mode\n",
            "update-alternatives: using /usr/bin/convert-im6.q16 to provide /usr/bin/convert-im6 (convert-im6) in auto mode\n",
            "update-alternatives: using /usr/bin/composite-im6.q16 to provide /usr/bin/composite (composite) in auto mode\n",
            "update-alternatives: using /usr/bin/composite-im6.q16 to provide /usr/bin/composite-im6 (composite-im6) in auto mode\n",
            "update-alternatives: using /usr/bin/conjure-im6.q16 to provide /usr/bin/conjure (conjure) in auto mode\n",
            "update-alternatives: using /usr/bin/conjure-im6.q16 to provide /usr/bin/conjure-im6 (conjure-im6) in auto mode\n",
            "update-alternatives: using /usr/bin/import-im6.q16 to provide /usr/bin/import (import) in auto mode\n",
            "update-alternatives: using /usr/bin/import-im6.q16 to provide /usr/bin/import-im6 (import-im6) in auto mode\n",
            "update-alternatives: using /usr/bin/identify-im6.q16 to provide /usr/bin/identify (identify) in auto mode\n",
            "update-alternatives: using /usr/bin/identify-im6.q16 to provide /usr/bin/identify-im6 (identify-im6) in auto mode\n",
            "update-alternatives: using /usr/bin/stream-im6.q16 to provide /usr/bin/stream (stream) in auto mode\n",
            "update-alternatives: using /usr/bin/stream-im6.q16 to provide /usr/bin/stream-im6 (stream-im6) in auto mode\n",
            "update-alternatives: using /usr/bin/display-im6.q16 to provide /usr/bin/display (display) in auto mode\n",
            "update-alternatives: using /usr/bin/display-im6.q16 to provide /usr/bin/display-im6 (display-im6) in auto mode\n",
            "update-alternatives: using /usr/bin/montage-im6.q16 to provide /usr/bin/montage (montage) in auto mode\n",
            "update-alternatives: using /usr/bin/montage-im6.q16 to provide /usr/bin/montage-im6 (montage-im6) in auto mode\n",
            "update-alternatives: using /usr/bin/mogrify-im6.q16 to provide /usr/bin/mogrify (mogrify) in auto mode\n",
            "update-alternatives: using /usr/bin/mogrify-im6.q16 to provide /usr/bin/mogrify-im6 (mogrify-im6) in auto mode\n",
            "Setting up imagemagick (8:6.9.11.60+dfsg-1.3ubuntu0.22.04.3) ...\n",
            "Processing triggers for hicolor-icon-theme (0.17-2) ...\n",
            "Processing triggers for libc-bin (2.35-0ubuntu3.4) ...\n",
            "/sbin/ldconfig.real: /usr/local/lib/libtbbmalloc.so.2 is not a symbolic link\n",
            "\n",
            "/sbin/ldconfig.real: /usr/local/lib/libtbbmalloc_proxy.so.2 is not a symbolic link\n",
            "\n",
            "/sbin/ldconfig.real: /usr/local/lib/libtbbbind_2_0.so.3 is not a symbolic link\n",
            "\n",
            "/sbin/ldconfig.real: /usr/local/lib/libtbb.so.12 is not a symbolic link\n",
            "\n",
            "/sbin/ldconfig.real: /usr/local/lib/libtbbbind.so.3 is not a symbolic link\n",
            "\n",
            "/sbin/ldconfig.real: /usr/local/lib/libtbbbind_2_5.so.3 is not a symbolic link\n",
            "\n",
            "Processing triggers for man-db (2.10.2-1) ...\n",
            "Processing triggers for fontconfig (2.13.1-4.2ubuntu5) ...\n",
            "Reading package lists... Done\n",
            "Building dependency tree... Done\n",
            "Reading state information... Done\n",
            "ghostscript is already the newest version (9.55.0~dfsg1-0ubuntu5.5).\n",
            "ghostscript set to manually installed.\n",
            "0 upgraded, 0 newly installed, 0 to remove and 15 not upgraded.\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m220.9/220.9 kB\u001b[0m \u001b[31m3.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m75.0/75.0 kB\u001b[0m \u001b[31m7.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m76.9/76.9 kB\u001b[0m \u001b[31m8.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m5.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n",
            "llmx 0.0.15a0 requires cohere, which is not installed.\n",
            "llmx 0.0.15a0 requires tiktoken, which is not installed.\u001b[0m\u001b[31m\n",
            "\u001b[0m"
          ]
        }
      ],
      "source": [
        "!pip install folium==0.2.1 --quiet\n",
        "!pip install pdflatex --quiet\n",
        "!apt-get install texlive-latex-recommended\n",
        "!apt install texlive-latex-extra\n",
        "!apt install dvipng\n",
        "!apt-get install imagemagick\n",
        "!apt-get install ghostscript\n",
        "!pip install openai --quiet"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 8,
      "metadata": {
        "id": "-FYNpZ4Yqjei"
      },
      "outputs": [],
      "source": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "QtQeIyjgD7f5"
      },
      "source": [
        "## Tikz to JPEG Utilities"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 9,
      "metadata": {
        "id": "sA-uQLktnFjL"
      },
      "outputs": [],
      "source": [
        "import subprocess\n",
        "import base64\n",
        "import os\n",
        "from tempfile import NamedTemporaryFile\n",
        "from IPython.display import display, Image\n",
        "import base64\n",
        "\n",
        "\n",
        "# Function to display the image\n",
        "def display_base64_image(base64_str):\n",
        "    display(Image(data=base64.b64decode(base64_str)))\n",
        "\n",
        "def remove_if_exists(filename):\n",
        "    if os.path.exists(filename):\n",
        "        os.remove(filename)\n",
        "\n",
        "def latex_to_base64_jpeg(latex_code, patience: int = 5):\n",
        "    # Create a temporary file for the LaTeX code\n",
        "    with NamedTemporaryFile(suffix=\".tex\", delete=False) as tex_file:\n",
        "        tex_filename = tex_file.name\n",
        "        tex_file.write(latex_code.encode('utf-8'))\n",
        "        tex_file.flush()\n",
        "\n",
        "        # Compile the LaTeX file into a PDF\n",
        "        result = subprocess.run(['pdflatex', '-output-directory', os.path.dirname(tex_filename), tex_filename], capture_output=True)\n",
        "        if result.returncode != 0:\n",
        "            print(f\"pdflatex failed with exit code: {result.returncode}, patience {patience}\")\n",
        "            output = result.stdout.decode()\n",
        "            error = result.stderr.decode()\n",
        "            if patience > 0:\n",
        "              print(f\"Attempting to fix!\")\n",
        "              fixed_latex = fix_latex(latex_code, error_message=output + \"\\n\\n\" + error)\n",
        "              return latex_to_base64_jpeg(fixed_latex, patience - 1)\n",
        "\n",
        "            return None\n",
        "\n",
        "        # Convert the produced PDF to a JPEG image\n",
        "        pdf_filename = tex_filename.replace('.tex', '.pdf')\n",
        "        if not os.path.exists(pdf_filename):\n",
        "            print(\"PDF file was not created.\")\n",
        "            remove_if_exists(tex_filename)\n",
        "            return None\n",
        "\n",
        "        jpeg_filename = tex_filename.replace('.tex', '.jpeg')\n",
        "        # result = subprocess.run(['convert', '-density', '300', pdf_filename, '-quality', '90', jpeg_filename], capture_output=True)\n",
        "        result = subprocess.run([\n",
        "            'gs',\n",
        "            '-sDEVICE=jpeg',\n",
        "            '-dPDFFitPage',\n",
        "            '-g512x512',\n",
        "            '-o', jpeg_filename,\n",
        "            '-r300',\n",
        "            pdf_filename\n",
        "        ], capture_output=True)\n",
        "\n",
        "        if result.returncode != 0:\n",
        "            print(\"convert failed with exit code:\", result.returncode)\n",
        "            output = result.stdout.decode()\n",
        "            error = result.stderr.decode()\n",
        "            if patience > 0:\n",
        "              print(f\"Attempting to fix!\")\n",
        "              fixed_latex = fix_latex(latex_code, error_message=output + \"\\n\\n\" + error)\n",
        "              return latex_to_base64_jpeg(fixed_latex, patience - 1)\n",
        "\n",
        "            return None\n",
        "\n",
        "        if not os.path.exists(jpeg_filename):\n",
        "            print(\"JPEG file was not created.\")\n",
        "            remove_if_exists(tex_filename)\n",
        "            remove_if_exists(pdf_filename)\n",
        "            return None\n",
        "\n",
        "        # Encode the JPEG image to base64\n",
        "        with open(jpeg_filename, \"rb\") as image_file:\n",
        "            encoded_string = base64.b64encode(image_file.read()).decode('utf-8')\n",
        "\n",
        "        remove_if_exists(tex_filename)\n",
        "        remove_if_exists(pdf_filename)\n",
        "        remove_if_exists(jpeg_filename)\n",
        "\n",
        "        return encoded_string\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 9,
      "metadata": {
        "id": "EQOeYUyHECdt"
      },
      "outputs": [],
      "source": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ESHd8LCgECrp"
      },
      "source": [
        "## Self-Refine Loop"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "FVA5zX9oEE1h"
      },
      "source": [
        "### Initialize\n",
        "\n",
        "* Note: the initial tikz is written by GPT-4, which the GPT-4V improves upon. GPT-4 is not used after the initial call, and the entire feedback -> refine process is handled by GPT4-V"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 10,
      "metadata": {
        "id": "PqaOvR7JEGOr"
      },
      "outputs": [],
      "source": [
        "import base64\n",
        "import requests\n",
        "import re\n",
        "import openai\n",
        "from openai import OpenAI\n",
        "from tqdm import tqdm\n",
        "\n",
        "\n",
        "\n",
        "def get_initial_latex(object_name, model=\"gpt-4-0613\"):\n",
        "    client = OpenAI(api_key=os.environ[\"OPEN_API_KEY\"])\n",
        "\n",
        "    # The \"simple\" here is intentional: I tried multiple variants: awesome, nice, cool.\n",
        "    # but starting with simple and refining leads to the lower error rates.\n",
        "    prompt = f\"\"\"Generate LaTeX code that draws a simple {object_name} using Tikz.\n",
        "Please make sure that the latex code is self-contained (no fancy packages except Tikz-related imports). Please don't forget to include \\\\usepackage{{tikz}} and \\\\usetikzlibrary{{shapes.geometric}}! Please use colors.\n",
        "I know it's a difficult task, try your best! Return your result in a  ```latex block\"\"\"\n",
        "\n",
        "    response = client.chat.completions.create(\n",
        "        model=model,\n",
        "        messages=[\n",
        "            {\"role\": \"system\", \"content\": \"You are a helpful assistant who can write Tikz code.\"},\n",
        "            {\"role\": \"user\", \"content\": prompt},\n",
        "        ],\n",
        "        temperature=0.0\n",
        "    )\n",
        "    return response\n",
        "\n",
        "\n",
        "def fix_latex(latex_code, error_message, model=\"gpt-4-0613\"):\n",
        "\n",
        "    client = OpenAI(api_key=os.environ[\"OPEN_API_KEY\"])\n",
        "    prompt = f\"\"\"Error log:\\n\\n{error_message}\n",
        "\n",
        "\n",
        "Buggy code:\n",
        "\n",
        "```latex\n",
        "{latex_code}\n",
        "```\n",
        "Please fix the bug and return the fixed code in a latex block ```latex.\"\"\"\n",
        "\n",
        "    response = client.chat.completions.create(\n",
        "        model=model,\n",
        "        messages=[\n",
        "            {\"role\": \"system\", \"content\": \"You are a helpful assistant who can write Tikz code.\"},\n",
        "            {\"role\": \"user\", \"content\": prompt},\n",
        "        ],\n",
        "        temperature=0.0\n",
        "    )\n",
        "    return extract_latex_from_response(response)\n",
        "\n",
        "\n",
        "\n",
        "def extract_latex_from_response(response):\n",
        "    # Check if the response is a dictionary and has the 'choices' key\n",
        "    if isinstance(response, openai.types.chat.chat_completion.ChatCompletion):\n",
        "      content = response.choices[0].message.content\n",
        "    elif isinstance(response, dict) and 'choices' in response:\n",
        "      content = response['choices'][0]['message']['content']\n",
        "    elif isinstance(response, str) and isinstance(json.loads(response), dict) and 'choices' in json.loads(response):\n",
        "      content = json.loads(response)['choices'][0]['message']['content']\n",
        "    else:\n",
        "      print(\"Invalid response format.\")\n",
        "      return None\n",
        "\n",
        "    # Define the regex pattern for LaTeX code block\n",
        "    latex_pattern = r\"```(?:latex|tex)\\n([\\s\\S]*?)\\n```\"\n",
        "\n",
        "\n",
        "    # Search for LaTeX code block\n",
        "    matches = re.search(latex_pattern, content)\n",
        "\n",
        "    # If a match is found, return the LaTeX code\n",
        "    if matches:\n",
        "        return matches.group(1)\n",
        "    else:\n",
        "        print(\"No LaTeX code block found.\")\n",
        "        return content\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "4CSX910-ENOt"
      },
      "source": [
        "### Feedback and Refine"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 11,
      "metadata": {
        "id": "ybMUFS_Qvknq"
      },
      "outputs": [],
      "source": [
        "def get_refinement_prompt(object_name):\n",
        "  return f\"\"\"This is the Tikz/Latex code for {object_name} shown in the picture. Can you improve it?\n",
        "\n",
        "First, understand the current picture.\n",
        "\n",
        "Then, think about how can it be improved.\n",
        "\n",
        "Then, rewrite the Tikz code to improve the image.\n",
        "\n",
        "Please make sure that the latex code is self-contained (no fancy packages except Tikz-related imports). Please don't forget to include \\\\usepackage{{tikz}} and \\\\usetikzlibrary{{shapes.geometric}}!\n",
        "\n",
        "Return your result in a  ```latex block\"\"\"\n",
        "\n",
        "\n",
        "\n",
        "def vlm_call(base64_image, latex_code, text_prompt, api_key):\n",
        "    headers = {\n",
        "        \"Content-Type\": \"application/json\",\n",
        "        \"Authorization\": f\"Bearer {api_key}\"\n",
        "    }\n",
        "\n",
        "    payload = {\n",
        "        \"model\": \"gpt-4-vision-preview\",\n",
        "        \"messages\": [\n",
        "            {\n",
        "                \"role\": \"user\",\n",
        "                \"content\": [\n",
        "                    {\n",
        "                        \"type\": \"image_url\",\n",
        "                        \"image_url\": {\n",
        "                            \"url\": f\"data:image/jpeg;base64,{base64_image}\"\n",
        "                        }\n",
        "                    },\n",
        "                    {\n",
        "                        \"type\": \"text\",\n",
        "                        \"text\": f\"```latex\\n\\n{latex_code}\\n\\n```{text_prompt}\"\n",
        "                    },\n",
        "\n",
        "                ]\n",
        "            }\n",
        "        ],\n",
        "        \"max_tokens\": 3000,\n",
        "        \"temperature\": 0.0\n",
        "    }\n",
        "\n",
        "    response = requests.post(\"https://api.openai.com/v1/chat/completions\", headers=headers, json=payload)\n",
        "    # print(response.json()['choices'][0]['message']['content'])\n",
        "    return response\n",
        "\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "Twl1NoUAv4cR"
      },
      "outputs": [],
      "source": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "uw52Gz9Qwy7b"
      },
      "source": [
        "### Self-Refine Loop"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 4,
      "metadata": {
        "id": "UKZCVSMmygg2"
      },
      "outputs": [],
      "source": [
        "import os\n",
        "import json\n",
        "from tqdm import tqdm\n",
        "os.environ[\"OPEN_API_KEY\"] = \"sk-\" #@param {type:\"string\"}"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 12,
      "metadata": {
        "id": "hmlDnhp2UJNz"
      },
      "outputs": [],
      "source": [
        "# Pick the object to draw\n",
        "object_name = \"sphere\" #@param {type:\"string\"}\n",
        "n_refine_loop = 5 #@param {type:\"slider\", min:2, max:10, step:1}"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 12,
      "metadata": {
        "id": "nAXpESRaJe7i"
      },
      "outputs": [],
      "source": []
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "DqTBQIgESISM",
        "outputId": "fa66ca29-988e-4127-94a6-5a3653bc0dbe"
      },
      "outputs": [
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "Drawing sphere:  20%|██        | 1/5 [00:08<00:35,  8.87s/it]"
          ]
        }
      ],
      "source": [
        "init_response = get_initial_latex(object_name)\n",
        "init_code = extract_latex_from_response(init_response)\n",
        "base64_image = latex_to_base64_jpeg(init_code)\n",
        "# Store the initial result\n",
        "results = [(init_code, init_response)]\n",
        "\n",
        "# Iteratively refine the LaTeX code\n",
        "num_exceptions_ok = 2\n",
        "for i in tqdm(range(n_refine_loop), desc=f\"Drawing {object_name}\"):\n",
        "  try:\n",
        "    base64_image = latex_to_base64_jpeg(init_code) or base64_image\n",
        "    if base64_image is None:\n",
        "      print(f\"Error in turn {i+1}\")\n",
        "      break\n",
        "    response = vlm_call(latex_code=init_code, base64_image=base64_image,\n",
        "                        text_prompt=get_refinement_prompt(object_name), api_key=os.environ[\"OPEN_API_KEY\"])\n",
        "    refined_code = extract_latex_from_response(response.json())\n",
        "\n",
        "    results.append((refined_code, response))\n",
        "    init_code = refined_code or init_code\n",
        "  except Exception as e:\n",
        "    if num_exceptions_ok > 0:\n",
        "      num_exceptions_ok -= 1\n",
        "      continue\n",
        "    else:\n",
        "      break\n",
        "    print(f\"Error in turn {i+1}\")\n",
        "\n",
        "\n",
        "\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "K_vfdq1zerey"
      },
      "outputs": [],
      "source": [
        "response.json()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "YBB7wnTvY-1x"
      },
      "source": [
        "\n",
        "Heads up: GPT4-V has been throwing a lot of:\n",
        "\n",
        "```js\n",
        "{'error': {'message': 'Something went wrong processing one of your images.',\n",
        "  'type': 'server_error',\n",
        "  'param': None,\n",
        "  'code': None}}\n",
        "```\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "UW8LCBvbHXcg"
      },
      "source": [
        "## See the Results"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "ZLbhTJi4aIgv"
      },
      "outputs": [],
      "source": [
        "import base64\n",
        "from PIL import Image, ImageDraw, ImageFont, ImageOps\n",
        "from io import BytesIO\n",
        "import imageio.v2 as imageio  # Use imageio version 2\n",
        "\n",
        "!rm *.png\n",
        "!rm *.gif\n",
        "\n",
        "import re\n",
        "\n",
        "def to_safe_filename(s):\n",
        "    s = re.sub(r'\\W|^(?=\\d)', '_', s)\n",
        "\n",
        "    if s[0].isdigit():\n",
        "        s = '_' + s\n",
        "\n",
        "    return s.lower()[:25]\n",
        "\n",
        "object_name = to_safe_filename(object_name)\n",
        "gif_file_name = f\"{object_name}.gif\"\n",
        "latex_codes_file_name = f\"{object_name}.json\"\n",
        "\n",
        "def base64_to_image(base64_string):\n",
        "    img_data = base64.b64decode(base64_string)\n",
        "    return Image.open(BytesIO(img_data))\n",
        "\n",
        "\n",
        "\n",
        "def save_annotated_images_from_latex(latex_codes, font_path='/usr/share/fonts/truetype/liberation/LiberationMono-Regular.ttf', font_size=50):\n",
        "    for i, latex_code in enumerate(latex_codes):\n",
        "      try:\n",
        "        image = base64_to_image(latex_to_base64_jpeg(latex_code, patience=2))\n",
        "\n",
        "        # Annotating the image with a larger font\n",
        "        draw = ImageDraw.Draw(image)\n",
        "        font = ImageFont.truetype(font_path, font_size)\n",
        "        text = f\"Step {i}\"\n",
        "        textwidth, textheight = draw.textbbox((0, 0), text, font=font)[2:]  # Get text size\n",
        "        x, y = image.width - textwidth - 10, image.height - textheight - 10\n",
        "        draw.text((x, y), text, font=font, fill=\"black\")\n",
        "\n",
        "        image.save(f\"annotated_{object_name}_{i+1}.png\")\n",
        "      except Exception as e:\n",
        "        print(f\"Error in saving image {i+1}\")\n",
        "\n",
        "\n",
        "def create_gif(image_count, fps=1, loop=0):\n",
        "    images = []\n",
        "    for i in range(image_count):\n",
        "        # check if image exists\n",
        "        if not os.path.exists(f\"annotated_{object_name}_{i+1}.png\"):\n",
        "            print(f\"Image {i+1} does not exist.\")\n",
        "            continue\n",
        "        images.append(imageio.imread(f\"annotated_{object_name}_{i+1}.png\"))\n",
        "    imageio.mimsave(gif_file_name, images, fps=fps, loop=loop)\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "MrN5-lnVaYdK"
      },
      "outputs": [],
      "source": [
        "# Extracting LaTeX codes from the results\n",
        "latex_codes = [latex_code for latex_code, _ in results]\n",
        "\n",
        "# Save annotated images\n",
        "save_annotated_images_from_latex(latex_codes)\n",
        "\n",
        "# Create and display GIF\n",
        "create_gif(len(latex_codes), fps=1, loop=0)  # Adjust fps as needed\n",
        "\n",
        "# Display the GIF in Colab\n",
        "from IPython.display import Image\n",
        "Image(open(gif_file_name,'rb').read())\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "hz7ge1Orl9BA"
      },
      "outputs": [],
      "source": [
        "from google.colab import files\n",
        "files.download(gif_file_name)\n",
        "tikz_code = [results[0] for results in results]\n",
        "with open(latex_codes_file_name, \"w\") as f:\n",
        "  for i in range(len(tikz_code)):\n",
        "    tmp = {\"object\": object_name, \"step\": i+1, \"code\": tikz_code[i]}\n",
        "    f.write(json.dumps(tmp) + \"\\n\")\n",
        "files.download(latex_codes_file_name)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "q3LBf67z8Qi_"
      },
      "source": []
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "nNu2sDJkKlU5"
      },
      "outputs": [],
      "source": []
    }
  ],
  "metadata": {
    "colab": {
      "authorship_tag": "ABX9TyOklujgUPVRkofN1eSl95MH",
      "include_colab_link": true,
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
